#pragma once
#include <string>
#include <vector>
#include <map>

namespace Ymsf {
	namespace Infras {

		class __declspec(dllexport) YMJson
		{
		public:
			enum Type {
				json_null=0,
				json_bool,
				json_int,
				json_double,
				json_string,
				json_array,
				json_object	
			};

		public:
			YMJson();
			YMJson(bool value);
			YMJson(int value);
			YMJson(double value);
			YMJson(const char* value);
			YMJson(const std::string& value);
			YMJson(Type type);
			YMJson(const YMJson& other);


			operator bool();
			operator int();
			operator double();
			operator std::string();

			YMJson& operator[](int index);
			void append(const YMJson& object);

			std::string Str();

			YMJson& operator[](const char*);
			YMJson& operator[](const std::string&);
			void operator=(const YMJson&);


		private:
			void copy();
			void clear();

		private:
			union Value
			{
				bool m_bool;
				int m_int;
				double m_double;
				std::string* m_string;
				std::vector<YMJson>* m_array;
				std::map<std::string, YMJson>* m_object;
			};

			Type m_type;
			Value m_value;


		};

	}
}



